<?php
session_start ();
// 判断用户是否已经登录
if (! isset ( $_SESSION ["userinfo"] ) and empty ( $_SESSION ["userinfo"] ["userid"] )) {
	header ( "location:../index.php" );
	session_unset ();
	session_destroy ();
	exit ();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<link href="../PersonalPhoto/Images/web_title.ico" rel="icon"
	type="image/x-icon" />
<title>搜缘</title>
<link href="./Resource/Style/base.yy.css" rel="stylesheet"
	type="text/css" />
<link href="./Resource/Style/souyuan.yy.css" rel="stylesheet"
	type="text/css" />
</head>
<body>
<?php
require_once '../tools/SqlHelper.class.php';
$myid = $_SESSION ["userinfo"] ["userid"];
// $myid = "xufeng520";
$myname = $_SESSION ["userinfo"] ["username"];
// $myname = "许峰";
$sqlHelper = new SqlHelper ();
$sql = "select count(user_tb_id) from `user_tb` where 1=1";
$row = $sqlHelper->execute_dql ( $sql );
$res = mysql_fetch_array ( $row );
$user_count = $res ['0'];
if (isset ( $_GET ['dazhaohu'] )) {
	// 获取浏览器发过来的页面数据
	$user_id = $_GET ['dazhaohu'];
	$user_name_d = $_GET ['user_name'] . "你好，很高兴认识你！！";
	// 创建一个SqlHelper对象
	$sql = "INSERT INTO `message_tb` (`user_receiver_id`, `user_send_id`, `ms_content`) VALUES ('$user_id', '$myid', '$user_name_d')";
	$res = $sqlHelper->execute_dql ( $sql );
	if (! ! $res) {
		echo "<script>alert('向" . $_GET ['user_name'] . "打招呼成功')</script>";
	} else {
		echo "<script>alert('向" . $_GET ['user_name'] . "打招呼失败')</script>";
	}
	$sql = "select user_id,ps_sex,ps_profession,ps_birthday_year,ps_apartment,ps_Icon,ps_education from `personal_data_tb` where 1=1";
	// 创建一个SqlHelper对象
	$row = $sqlHelper->execute_dql ( $sql );
	$now_data = getdate ();
} else if (isset ( $_POST ['user_submit'] ) and $_POST ['user_submit'] == '搜索') {
	// 获取浏览器发过来的页面数据
	$now_data = getdate ();
	$sel_sex = $_POST ['sel_sex'];
	$sql = "";
	if ($_POST ['sel_age_min'] == "0" || $_POST ['sel_age_max'] == "0") {
		// echo "<script>alert('*** 1 ***')</script>";
		if ($_POST ['s_province'] != "省级") {
			if ($_POST ['s_city'] != "地级市") {
				// echo "<script>alert('*** 2 ***')</script>";
				$ps_apartment = $_POST ['s_province'] . "%%" . $_POST ['s_city'];
			} else {
				// echo "<script>alert('*** 3 ***')</script>";
				$ps_apartment = $_POST ['s_province'];
			}
			$sql = "select user_id,ps_sex,ps_profession,ps_birthday_year,ps_apartment,ps_Icon,ps_education from `personal_data_tb` where `ps_sex` = '$sel_sex' and `ps_apartment` LIKE '%%$ps_apartment%%'";
		} else {
			// echo "<script>alert('*** 4 ***')</script>";
			$sql = "select user_id,ps_sex,ps_profession,ps_birthday_year,ps_apartment,ps_Icon,ps_education from `personal_data_tb` where `ps_sex` = '$sel_sex'";
		}
	} else if ($_POST ['s_province'] != "省级") {
		// echo "<script>alert('*** 5 ***')</script>";
		$sel_age_min = $now_data ["year"] - ( int ) $_POST ['sel_age_min'];
		$sel_age_max = $now_data ["year"] - ( int ) $_POST ['sel_age_max'];
		if ($_POST ['s_city'] != "地级市") {
			// echo "<script>alert('*** 6 ***')</script>";
			$ps_apartment = $_POST ['s_province'] . "%%" . $_POST ['s_city'];
		} else {
			$ps_apartment = $_POST ['s_province'];
		}
		$sql = "select user_id,ps_sex,ps_profession,ps_birthday_year,ps_apartment,ps_Icon,ps_education from `personal_data_tb` 
			where `ps_sex` = '$sel_sex' and `ps_apartment` LIKE '%%$ps_apartment%%' and `ps_birthday_year` between $sel_age_max and $sel_age_min";
	} else {
		// echo "<script>alert('*** 8 ***')</script>";
		$sel_age_min = $now_data ["year"] - ( int ) $_POST ['sel_age_min'];
		$sel_age_max = $now_data ["year"] - ( int ) $_POST ['sel_age_max'];
		$sql = "select user_id,ps_sex,ps_profession,ps_birthday_year,ps_apartment,ps_Icon,ps_education
		from `personal_data_tb` where `ps_sex` = '$sel_sex' and `ps_birthday_year` between $sel_age_max and $sel_age_min";
	}
	$row = $sqlHelper->execute_dql ( $sql );
} else {
	$sql = "select user_id,ps_sex,ps_profession,ps_birthday_year,ps_apartment,ps_Icon,ps_education from `personal_data_tb` where 1=1";
	// 创建一个SqlHelper对象
	$row = $sqlHelper->execute_dql ( $sql );
	$now_data = getdate ();
}
?>
	<div class="yy_header">
		<div class="yy_nav">
			<span class="logo" title="找对象，上友缘网！"
				style="background-image: url('../PersonalPhoto/Images/logo.png');"><a
				href="#"></a></span>
			<ul>
				<li><a class="a_01" href="../Space/SpaceIndex.php"><span
						style="background-image: url('../PersonalPhoto/Images/Space.png');"></span>空间</a></li>
				<li><a class="a_01 a_out" href="#"><span
						style="background-image: url('../PersonalPhoto/Images/Search.png');"></span>搜缘</a></li>
				<li><a class="a_01" href="../Serve/ServeIndex.php"><span
						style="background-image: url('../PersonalPhoto/Images/Serve.png');">
					</span>服务</a></li>
				<li><a class="a_01" href="../Mailbox/MailboxIndex.php"><span
						style="background-image: url('../PersonalPhoto/Images/Mailbox.png');"></span>信箱</a></li>
			</ul>
			<div id="mineInfo" class="set_up ">
				<em class="tipParent"></em> <span style="font-size: 16px;"
					title="<?php echo $myname;?>">你好，<?php echo $_SESSION ["userinfo"] ["username"];?>
					<a style="font-size: 12px;" href="../index.php?exit=1">安全退出</a></span>
			</div>
		</div>
	</div>
	<div class="student condition "></div>
	<div class="les_nav">
		<ul class="nav">
			<li class="searchTab current"><a href="#" class="current"
				style="border-left: none;">条件搜索</a></li>
		</ul>
		<form action="./SearchMarginIndex.php" method="post">
			<ol class="searchList select">
				<li id="baseSearch" class="adress"><label>我要找居住在</label><em></em>
					<div class="local tipParent searchTip active">
						<select id="s_province" name="s_province" class="popup_item"></select>
					</div>
					<div class="local tipParent searchTip active old_01">
						<select id="s_city" name="s_city" class="show_item active"></select>
						<script src="./Resource/Style/area.js" type="text/javascript"></script>
						<script type="text/javascript">_init_area("安徽省");</script>
					</div> <label class="age">年龄</label><em></em>
					<div class="old_01 tipParent searchTip active">
						<select name="sel_age_min">
					<?php
					echo "<option class='selectList value=0 selected='true'>不限制</option>";
					for($i = 18; $i < 50; $i ++) {
						echo "<option class='selectList' value=" . $i . ">" . $i . "岁</option>";
					}
					?>
					</select>
					</div> <label class="stance">-</label><em></em>
					<div class="old_01 tipParent searchTip active">
						<select name="sel_age_max">
					<?php
					echo "<option class='selectList' value=0 selected='true'>不限制</option>";
					for($i = 18; $i < 50; $i ++) {
						echo "<option class='selectList' value=" . $i . ">" . $i . "岁</option>";
					}
					?>
					</select>
					</div> <label>的</label><em></em>
					<div class="old_01 tipParent searchTip active">
						<select name="sel_sex" class="show_item active">
							<option value="1" selected="true">女朋友</option>
							<option value="0">男朋友</option>
						</select>
					</div> <input class="seach" name="user_submit" type="submit"
					value="搜索" /></li>
				<li id="expandSearch" class="trg">
					<div class="dredge">
						<a href="#" class="pink">开通桃花会员</a>可使用更多条件
					</div>
					<div class="old_01">
						<span>学历</span><em></em>
					</div>
					<div class="old_01">
						<span>月收入</span><em></em>
					</div>
					<div class="old_01">
						<span>住房</span><em></em>
					</div>
					<div class="old_01">
						<span>星座</span><em></em>
					</div>
					<div class="old_01">
						<span>婚史</span><em></em>
					</div>
				</li>
			</ol>
		</form>
	</div>
	<!--学生征婚网start-->
	<div class="student">
		<h3>
			友缘征婚网<font>当前有<span class="pink"><?php echo $user_count;?></span>人在线征婚交友
			</font>
		</h3>
		<ul class="mian search_list">
		<?php
		$num = 0;
		while ( $res = mysql_fetch_assoc ( $row ) ) {
			$user_id = $res ['user_id'];
			if ($user_id != $_SESSION ["userinfo"] ["userid"]) {
				$ps_profession = $res ['ps_profession'];
				$ps_birthday_year = $res ['ps_birthday_year'];
				$user_sex_w = $res ['ps_sex'];
				if ($user_sex_w == "0") {
					$user_sex_w = "帅哥";
				} else {
					$user_sex_w = "美女";
				}
				$ps_apartment = $res ['ps_apartment'];
				if ($ps_apartment == "0") {
					$ps_apartment = "地址未填写";
				}
				$ps_Icon = $res ['ps_Icon'];
				if ($ps_Icon == "0") {
					$ps_Icon = "../PersonalPhoto/Images/nohead_new.jpg";
				} else {
					$ps_Icon = "../PersonalPhoto/" . $user_id . "/" . $ps_Icon;
				}
				$sql2 = "select user_name from `user_tb` where `user_id`='$user_id'";
				$row2 = $sqlHelper->execute_dql ( $sql2 );
				$res2 = mysql_fetch_array ( $row2 );
				$user_name_w = $res2 ['user_name'];
				$ps_birthday_year = ($now_data ["year"] - ( int ) $ps_birthday_year);
				$ps_education_w = $res ['ps_education'];
				if ($ps_education_w == "5") {
					$ps_education_w = "初中及以下";
				} else if ($ps_education_w == "1") {
					$ps_education_w = "高中及中专";
				} else if ($ps_education_w == "2") {
					$ps_education_w = "大专";
				} else if ($ps_education_w == "3") {
					$ps_education_w = "本科";
				} else if ($ps_education_w == "4") {
					$ps_education_w = "硕士及以上";
				} else {
					$ps_education_w = "学历未填写";
				}
				if ((++ $num % 3) == 0) {
					echo "<li class='last_li search_user_item'>";
				} else {
					echo "<li class='search_user_item'>";
				}
				echo "<dl>";
				echo "<dt>";
				echo "<a target='new' href='../PersonalSpace/PersonalSpace.php?user_id=" . $user_id . "'><img alt='征婚交友信息' src='" . $ps_Icon . "' width='112' height='138' /></a>";
				echo "</dt>";
				echo "<dd>";
				echo "<a target='new' href='../PersonalSpace/PersonalSpace.php?user_id=" . $user_id . "'><strong >" . $user_name_w . "</strong></a>";
				echo "<font>" . $user_sex_w . " | " . $ps_birthday_year . "岁<br>" . $ps_education_w . "</font>";
				echo "<span class='blue'>" . $ps_apartment . "</span>";
				echo "<a href='./SearchMarginIndex.php?dazhaohu=" . $user_id . "&user_name=" . $user_name_w . "' class='sayHiBtnP hello'><span>打招呼</span></a>";
				echo "</dd>";
				echo "</dl>";
				echo "</li>";
			}
		}
		// 关闭连接
		mysql_free_result ( $row );
		$sqlHelper->close_connect ();
		?>
			<div class="clear"></div>
		</ul>
	</div>
</body>
</html>